package com.fz.study.project.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author Administrator
 * @description TODO
 * @date 2024/2/16 16:06
 */
@Component
//@Aspect
@Slf4j
public class TimeAspect {

//    统一配置切入点表达式
    @Pointcut("execution(* com.fz.study.project.service.*.*(..))")
    private void pt(){

    }

    @Around("pt()")
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        //获取开始时间
        Long begin = System.currentTimeMillis();
//        调用原始方法运行
        Object result = joinPoint.proceed();
//        获取结束时间
        Long end = System.currentTimeMillis();
        log.info(joinPoint.getSignature()+",该方法一共耗时{}ms",+(end - begin));
        return result;
    }
}
